home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Utilities / Programming / Snippets 2.4 / Snippets / Snippets.rsrc / TEXT_403_3.txt < prev    next >
Encoding:
Text File  |  1996-01-21  |  6.6 KB  |  298 lines

  1. /**********************************************************************
  2.  
  3.     MainWindow.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. #include "Fn_Prototypes.h"
  8. #include "SampleDialog.h"
  9. #include "SampleList.h"
  10.  
  11. #define DRAG_THRESHOLD 30
  12. #define DIALOG_BUTTON  400
  13. #define LIST_BUTTON    401
  14. #define AE_BUTTON      402
  15. #define ERR_BUTTON     403
  16. #define TBD_BUTTON     404
  17.  
  18. extern int gNewWindowLeft;
  19. extern int gNewWindowTop;
  20.  
  21. extern struct SysConfigRec
  22. {
  23.     Boolean hasGestalt;
  24.     Boolean hasWNE;
  25.     Boolean hasColorQD;
  26.     Boolean hasAppleEvents;
  27.     Boolean hasEditionMgr;
  28.     Boolean hasHelpMgr;
  29.  
  30.     long    sysVersion;
  31. };
  32. extern struct SysConfigRec gSysConfig;
  33.  
  34.  
  35. /********** Prototypes */
  36. void MyCreateWindow(       short       winID,
  37.                            Ptr         winRec,
  38.                            WindowPtr   behind,
  39.                            int         top,
  40.                            int         left,
  41.                            int         offset,
  42.                            int         errID );
  43. void MyDoContent(          WindowPtr   w,
  44.                            EventRecord *e );
  45. void MyDoUpdateWindow(     WindowPtr   w );
  46. void MyDoActivateWindow(   WindowPtr   w );
  47. void MyDoDeactivateWindow( WindowPtr   w );
  48.  
  49.  
  50. /********** CreateWindow */
  51.  
  52. void MyCreateWindow( short     winID,
  53.                      Ptr       winRec,
  54.                      WindowPtr behind,
  55.                      int       top,
  56.                      int       left,
  57.                      int       offset,
  58.                      int       errID )
  59. {
  60.     WindowPtr     w;
  61.     ControlHandle c;
  62.  
  63.     if( gSysConfig.hasColorQD )
  64.     {
  65.         if ( ( w = GetNewCWindow( winID, winRec, behind ) ) == nil )
  66.             FnErr_DisplayStrID( errID, TRUE );
  67.     }
  68.     else
  69.     {
  70.         FnErr_DisplayStr( "\pColor QuickDraw not supported! ",
  71.                           "\pPlease upgrade your machine!",
  72.                           "\p",
  73.                           "\p",
  74.                           TRUE );
  75.     }
  76.  
  77.     if (((qd.screenBits.bounds.right - gNewWindowLeft) < DRAG_THRESHOLD) ||
  78.         ((qd.screenBits.bounds.bottom - gNewWindowTop) < DRAG_THRESHOLD))
  79.     {
  80.         gNewWindowLeft = left;
  81.         gNewWindowTop = top;
  82.     }
  83.     
  84.     MoveWindow( w, gNewWindowLeft, gNewWindowTop, FALSE );
  85.     gNewWindowLeft += offset;
  86.     gNewWindowTop += offset;
  87.     
  88.     c = GetNewControl( DIALOG_BUTTON, w );
  89.     (**c).contrlRfCon = DIALOG_BUTTON;
  90.     c = GetNewControl( LIST_BUTTON, w );
  91.     (**c).contrlRfCon = LIST_BUTTON;
  92.     c = GetNewControl( AE_BUTTON, w );
  93.     (**c).contrlRfCon = AE_BUTTON;
  94.     c = GetNewControl( ERR_BUTTON, w );
  95.     (**c).contrlRfCon = ERR_BUTTON;
  96.     c = GetNewControl( TBD_BUTTON, w );
  97.     (**c).contrlRfCon = TBD_BUTTON;
  98.     
  99.     ShowWindow( w );
  100.     DrawControls( w );
  101. }
  102.  
  103.  
  104. /********** DoContent */
  105.  
  106. void MyDoContent( WindowPtr w, EventRecord *e )
  107. {
  108.     ControlHandle c;
  109.     GrafPtr       savePort;
  110.     Point         theLocation;
  111.     short         theClick;
  112.     int           theResponse;
  113.  
  114.     StandardFileReply  mySFR;
  115.     SFTypeList         myTypeList;
  116.     // OSErr              myErr;
  117.     // Str255             myApp = "\pEditor";
  118.     // FSSpec             mySpec;
  119.  
  120.     savePort = qd.thePort;
  121.     SetPort( w );
  122.     theLocation = (*e).where;
  123.     GlobalToLocal( &theLocation );
  124.     theClick = FindControl( theLocation, w, &c );
  125.     if( theClick == inButton )
  126.     {
  127.         theResponse = TrackControl( c, theLocation, nil );
  128.         if( theResponse != 0 )
  129.         {
  130.             switch( (**c).contrlRfCon )
  131.             {
  132.                  case DIALOG_BUTTON:
  133.                      MySampleDialog();
  134.                      break;
  135.                  case LIST_BUTTON:
  136.                      MyListDialog();
  137.                      break;
  138.                  case AE_BUTTON:
  139.                      myTypeList[0] = 'TEXT';
  140.                      myTypeList[1] = 'APPL';
  141.                      StandardGetFile(nil,2,myTypeList,&mySFR);
  142.                      if( mySFR.sfGood )
  143.                         FnAE_SendOpenAE(&(mySFR.sfFile));
  144.                      //
  145.                      // option
  146.                      //
  147.                      // myErr = FSMakeFSSpec(0,0,myApp,&mySpec);
  148.                      // if( myErr == noErr )
  149.                      //     FnAE_SendOpenAE(&mySpec);
  150.                      //
  151.                      break;
  152.                  case ERR_BUTTON:
  153.                      FnErr_DisplayStr(
  154.                          "\pThis is a test ",
  155.                          "\pto see if this error ",
  156.                          "\pmessage is displayed...",
  157.                          "\p",
  158.                          FALSE );
  159.                      break;
  160.                  case TBD_BUTTON:
  161.                      break;
  162.                  default:
  163.                      break;                        
  164.             }
  165.         }
  166.     }
  167.     SetPort( savePort );
  168. }
  169.  
  170.  
  171. /********** MyDoUpdateWindow */
  172.  
  173. void MyDoUpdateWindow( WindowPtr w )
  174. {
  175.     GrafPtr savePort;
  176.     
  177.     GetPort( &savePort );
  178.     SetPort( w );
  179.     BeginUpdate( w );
  180.         DrawControls( w );
  181.     EndUpdate( w );
  182.     SetPort( savePort );
  183. }
  184.  
  185.  
  186. /********** MyDoActivateWindow */
  187.  
  188. void MyDoActivateWindow( WindowPtr w )
  189. {
  190.     GrafPtr       savePort;
  191.     ControlHandle cntl;
  192.     
  193.     GetPort( &savePort );
  194.     SetPort( w );
  195.         cntl = ((WindowPeek)(w))->controlList;
  196.         while( cntl != 0 )
  197.         {
  198.             HiliteControl( cntl, 0 );
  199.             cntl = (*cntl)->nextControl;
  200.         }
  201.         DrawControls( w );
  202.     SetPort( savePort );
  203. }
  204.  
  205.  
  206. /********** MyDoDeactivateWindow */
  207.  
  208. void MyDoDeactivateWindow( WindowPtr w )
  209. {
  210.     GrafPtr       savePort;
  211.     ControlHandle cntl;
  212.     
  213.     GetPort( &savePort );
  214.     SetPort( w );
  215.         cntl = ((WindowPeek)(w))->controlList;
  216.         while( cntl != 0 )
  217.         {
  218.             HiliteControl( cntl, 255 );
  219.             cntl = (*cntl)->nextControl;
  220.         }
  221.         DrawControls( w );
  222.     SetPort( savePort );
  223. }
  224.  
  225.  
  226. /**********************************************************************
  227.  
  228.     MainWindow.r
  229.  
  230. ***********************************************************************/
  231.  
  232. #include <Types.r>
  233.  
  234. resource 'WIND' (400, "Main Window") {
  235.     {50, 10, 223, 125},
  236.     noGrowDocProc,
  237.     invisible,
  238.     goAway,
  239.     0x0,
  240.     "Window"
  241. };
  242.  
  243. resource 'CNTL' (400, "Dialog") {
  244.     {13, 30, 33, 90},
  245.     0,
  246.     visible,
  247.     0,
  248.     0,
  249.     pushButProc,
  250.     0,
  251.     "Dialog"
  252. };
  253.  
  254. resource 'CNTL' (401, "List") {
  255.     {46, 30, 66, 90},
  256.     0,
  257.     visible,
  258.     0,
  259.     0,
  260.     pushButProc,
  261.     0,
  262.     "List"
  263. };
  264.  
  265. resource 'CNTL' (402, "AEvent") {
  266.     {79, 30, 99, 90},
  267.     0,
  268.     visible,
  269.     0,
  270.     0,
  271.     pushButProc,
  272.     0,
  273.     "AEvent"
  274. };
  275.  
  276. resource 'CNTL' (403, "Error") {
  277.     {112, 30, 132, 90},
  278.     0,
  279.     visible,
  280.     0,
  281.     0,
  282.     pushButProc,
  283.     0,
  284.     "Error"
  285. };
  286.  
  287. resource 'CNTL' (404, "TBD") {
  288.     {145, 30, 165, 90},
  289.     0,
  290.     visible,
  291.     0,
  292.     0,
  293.     pushButProc,
  294.     0,
  295.     "???"
  296. };
  297.  
  298. // End of File